package com.zhike.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhike.domain.DwsAlarmWindow;
import com.zhike.mapper.DwsAlarmBtWindowMapper;
import com.zhike.service.DwsAlarmWindowService;
import com.zhike.mapper.DwsAlarmWindowMapper;
import com.zhike.utils.BarUtils;
import com.zhike.utils.FormUtils;
import com.zhike.utils.Result;
import com.zhike.utils.ResultCodeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* @author ASUS
* @description 针对表【dws_alarm_window(车辆告警表)】的数据库操作Service实现
* @createDate 2024-05-01 21:05:55
*/
@Service
public class DwsAlarmWindowServiceImpl extends ServiceImpl<DwsAlarmWindowMapper, DwsAlarmWindow>
    implements DwsAlarmWindowService{
    @Autowired
    private DwsAlarmWindowMapper dwsAlarmWindowMapper;



    @Override
    public String getAlarmCountToday(String filter) {
        String date = BarUtils.getDate(filter);
        try {
            List<Map> avgTypeToday = dwsAlarmWindowMapper.getAlarmCountToday(date);
            Map data = FormUtils.getDeail(avgTypeToday,"汽车编码","vin");
            return Result.ok(JSON.toJSONString(data)).toString();
        } catch (Exception e) {
            return Result.build(null, ResultCodeEnum.FAIL).toString();
        }
    }



    @Override
    public String getAlarmCountWeek(String filter) {
        String date = BarUtils.getDate(filter);
        try {
            List<Map> avgTypeToday = dwsAlarmWindowMapper.getAlarmCountWeek(date);
            Map data = FormUtils.getDeail(avgTypeToday,"汽车编码","vin");
            return Result.ok(JSON.toJSONString(data)).toString();
        } catch (Exception e) {
            return Result.build(null, ResultCodeEnum.FAIL).toString();
        }
    }
}




